#coding:utf-8
import time
import datetime
import random
import json
import urllib2
class Tool(object):
    def check_param(self,mustkeys,cfgParam):
        func = cfgParam["cmd"]
        ret = {'status':0}  
        flag = 1
        ret["info"] = func + " missing parameter: "
        for key in mustkeys:
            if key not in cfgParam.keys():
                ret["info"] = ret["info"] + key + " "
                flag = 0
                
        if flag:
            ret["status"] = 1
            ret["info"] = func +" param normal."
        return ret  

    def trans_minute(self,obtime):
        h,m=obtime.strip().split(":")
        return int(h)*60+int(m)
    
    def judge_daytype(self):
        whichday = datetime.datetime.now().weekday()
        if whichday <5:
            return "weekday"
        else :
            return "weekend"
    def judgeDaytype(self):

        date = time.strftime("%Y%m%d")
	server_url = "http://api.goseek.cn/Tools/holiday?date=" 
	vop_url_request = urllib2.Request(server_url+date)  
	vop_response = urllib2.urlopen(vop_url_request)  
	vop_data= json.loads(vop_response.read())  
	if vop_data["data"]==1:  
	    return "weekend"  
        else:  
            return "weekday"


    def createPhoneCode(self):  
        chars=['0','1','2','3','4','5','6','7','8','9']  
	x = random.choice(chars),random.choice(chars),random.choice(chars),random.choice(chars)  
	verifyCode = "".join(x)  
        return verifyCode  
